package com.yanqu.road.server.cmd.kuang;

import com.yanqu.road.entity.kuang.KuangConfig;
import com.yanqu.road.entity.kuang.battle.CrossKuangBattlePosition;
import com.yanqu.road.logic.pb.CrossKuangPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.kuang.Kuang;
import com.yanqu.road.server.cmd.CrossAppointCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.kuang.CrossKuangMgr;
import com.yanqu.road.server.manager.kuang.activity.CrossKuangActivity;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;

@Cmd(code = CrossProtocol.C_CROSS_KUANG_OFF_LINE, desc = "玩家离线操作")
public class CrossKuangBattleOffLineCmd extends CrossAppointCommand {

    private int groupId;

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        Kuang.CrossKuangOffLineReqMsg reqMsg = Kuang.CrossKuangOffLineReqMsg.parseFrom(packet.getBytes());
        groupId = reqMsg.getGroupId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossKuangActivity activity = CrossKuangMgr.getActivity(groupId);
        if (activity == null) {
            ret = GameErrorCode.E_KUANG_BATTLE_ACTIVITY_NOT_FOUND;
            return;
        }
        KuangConfig config = activity.getConfig();
        if (config == null) {
            ret = GameErrorCode.E_KUANG_CONFIG_NOT_FOUND;
            return;
        }
        activity.offLineByCmd(userId);
    }

    @Override
    public void sendData() {

    }
}
